#!/usr/bin/perl

system("cat a.out |grep \"Phase1\" > time1.txt");
system("cat a.out |grep \"Phase2\" > time2.txt");
system("cat a.out |grep \"Phase3\" > time3.txt");
system("cat a.out |grep \"Phase4\" > time4.txt");

open(OUTPUT, ">result.txt") or die "result.txt cannot be created.\n";
open(INPUT, "time1.txt") or die "time.txt cannot be opened.\n";

$counter= `cat time1.txt | wc -l`;
print "$counter\n";

for($i=1; $i<=4; $i++)
{
	$in = "time".$i.".txt";
	open(INPUT, $in) or die "$in cannot be opened.\n";
	$total_time=0;
	while($line = <INPUT>)
	{
		chomp($line);
		@line_block = split(' ', $line);
		$total_time = $total_time + $line_block[4];
	}
	#print "$i total $total_time\n";
	$avg = $total_time / $counter / 1000;
	#print "$i avg $avg\n";
	print "$avg ";
}

close(INPUT);
close(OUTPUT);

